---
title: 'Replication File: White Americans’ Reactions to Racial Disparities in COVID-19' 
author: 'LaFleur Stephens-Dougan'
output: pdf_document
header-includes:
    - \usepackage{caption}
    - \usepackage{fvextra}
    - \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}}
classoption: landscape
---

\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}
\renewcommand{\thefigure}{A\arabic{figure}}
\captionsetup[table]{labelformat=empty}

```{r setup, include=FALSE}
library(knitr)
library(formatR)
knitr::opts_chunk$set(echo = TRUE, tidy=TRUE, tidy.opts=list(width.cutoff=55))
```

**Preliminary Notes**

- I fielded a survey experiment on an online nationally representative sample of 591 Whites between May 21 and May 26, 2020. The online sample was collected by the National Opinion Research Center (NORC) at the University of Chicago, using their AmeriSpeak Panel. Below I include the code to reproduce the figures and tables included in the paper and the Appendix. 

- I used Stata to generate variable coding. Please use the Stata do file - **variablecoding-final.do** - for reproducing the analysis sample and variables. 

- I load R packages and functions that will be used in the analysis. 

```{r include=T, message=FALSE, warning=FALSE}
## packages 
library(dplyr)
library(ggplot2)
library(haven)
library(readr)
library(survey)
library(estimatr)
library(texreg)
library(xtable)
library(stargazer)
library(kableExtra)
library(tidyr)
library(tibble)
library(tinytex)
library(stringr)
library(multcomp)
library(magrittr)
library(sandwich)
library(pwr)
library(aod)
library(arm)
library(psych)
library(purrr)
library(cobalt)
library(forcats)
library(jtools)
```

# 1. Load Data 

- To run the analyses, you must load the **Tess_Covid_update_wvars.dta** and **pilotData_June2021.tab**, as shown below.

```{r include = T, tidy=T}
## load the data
data <- read_dta('data/Tess_Covid_update_wvars.dta') 
## load the pilot data 
data_pilot <- read_dta('data/PilotData_June2021.dta')
```

# 2. Analyses

- The code below reproduces figures and tables of the main text and Appendix. 

```{r include = T, tidy=T}
## specify a survey design 
svydata <-  svydesign(id = ~ CaseId , weights = ~ WEIGHT, data = data)
```

## Logistic Regression Models with Survey Weights

- The code below reproduces amended **Table 1 (amended): The Influence of Racial Disparities Information and Negative Stereotype Endorsement on COVID-19 Opinion** in the main text.

```{r include = T, tidy=T, warning=F}
## logit regression models using svyglm()
masks_svyglm <- svyglm(facemasks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), design = svydata)
rights_svyglm <- svyglm(individualrights_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), design = svydata)
parks_svyglm <- svyglm(visitparks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), design = svydata)
socld_svyglm <- svyglm(Follow_Blacks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), design = svydata)
```

- Calculate one-tailed p-values for wearing masks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(masks_svyglm)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(masks_svyglm)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
masks_svyglm_onetailed <- pnorm(summary(masks_svyglm)$coefficients[,3], lower = F)
# masks_svyglm_onetailed
```

- Calculate one-tailed p-values for individual rights and freedoms threatened 

```{r include = T, tidy=T}
# # manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(rights_svyglm)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(rights_svyglm)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
rights_svyglm_onetailed <- pnorm(summary(rights_svyglm)$coefficients[,3], lower = F)
# rights_svyglm_onetailed
```

- Calculate one-tailed p-values for visit parks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(parks_svyglm)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(parks_svyglm)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
## Store and use for assessing p-values in regression table
parks_svyglm_onetailed <- pnorm(summary(parks_svyglm)$coefficients[,3], lower = F)
# parks_svyglm_onetailed
```

- Calculate one-tailed p-values for following social distancing rules 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(socld_svyglm)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(socld_svyglm)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
## store and use for assessing p-values in regression table
socld_svyglm_onetailed <- pnorm(summary(socld_svyglm)$coefficients[,3], lower = F)
# socld_svyglm_onetailed
```

```{r include = T, tidy = T, results='asis', tidy.opts=list(width.cutoff=60)}
stargazer(masks_svyglm, rights_svyglm, parks_svyglm, socld_svyglm,
          title = "Table 1 (amended): The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion", 
          dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", 
                               "Racial Disparities Information X Negative Stereotype Endorsement",  
                               "Constant"),
          no.space = T, 
          column.sep.width = "1pt",
          font.size = "small", 
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."), p.auto = FALSE, p = list(masks_svyglm_onetailed, rights_svyglm_onetailed, parks_svyglm_onetailed, socld_svyglm_onetailed), notes.append = FALSE
)
```

\clearpage 

## The Effects of Racial Disparities Information

The code below reproduces amended **Figure 1: The Effects of Racial Disparities Information (Racially Prejudiced Whites)**

```{r include = T, tidy = T, results='asis'}
## compute estimated predicted values 
maskssvyglmpr <- ggeffects::ggpredict(masks_svyglm, terms = c("negstereotype_endorsement [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Wearing \n facemasks is not \n important")
rightssvyglmpr <- ggeffects::ggpredict(rights_svyglm, terms = c("negstereotype_endorsement [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Individual rights and \n freedom threatened")
parkssvyglmpr <- ggeffects::ggpredict(parks_svyglm, terms = c("negstereotype_endorsement [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Visit parks \n without any \n restrictions")
socldsvyglmpr <- ggeffects::ggpredict(socld_svyglm, terms = c("negstereotype_endorsement [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Black people rarely \n follow social \n distancing guidelines")
# save the data frame
predictions <- bind_rows(as_tibble(maskssvyglmpr), 
                        as_tibble(rightssvyglmpr), 
                        as_tibble(parkssvyglmpr), 
                        as_tibble(socldsvyglmpr))
predictions <- predictions %>%
  dplyr::rename(Treatment = group, 
         Attitude = x) %>%
  relocate(dv) %>%
  as_tibble() %>%
  mutate(Treatment = as.numeric(Treatment), 
         Attitude = as.numeric(Attitude), 
         Att_Treat = case_when(Attitude == 0 & Treatment == 1 ~ "Non-prejudiced, control", 
                               Attitude == 0 & Treatment == 2 ~ "Non-prejudiced, treatment", 
                               Attitude == 1 & Treatment == 1 ~ "Prejudiced, control", 
                               Attitude == 1 & Treatment == 2 ~ "Prejudiced, treatment"), 
         Att_Treat = as_factor(Att_Treat), 
         Figure = if_else(Attitude == 1, "Figure 1", "Figure 2"), 
         Treatment = as_factor(Treatment), 
         Treatment = fct_recode(Treatment, Control = "1", 
                                Treatment= "2"))
## create a factor variable for DVs
predictions$dv_f <- factor(predictions$dv, levels = c("Wearing \n facemasks is not \n important", "Individual rights and \n freedom threatened", "Black people rarely \n follow social \n distancing guidelines", "Visit parks \n without any \n restrictions"))
## plot the  estimated predicted values for racially prejudiced whites 
predictions %>%
  filter(Attitude == 1) %>%
  ggplot(aes(x=Treatment, y = predicted, group = dv_f)) + ggtitle("Figure 1 (amended): The Effects of Racial Disparities \n Information (Racially Prejudiced Whites)") +
  geom_bar(aes(fill = Treatment), stat= "identity") +
  geom_errorbar( aes(x=Treatment, ymin=conf.low, ymax=conf.high), width=0.1) +
  facet_wrap(~dv_f) +
  theme_bw() +
  ylim(0, 1) + scale_fill_manual("Group", values = c(Treatment = "grey36", Control = "grey")) + ylab("Predicted Probability") + xlab("") +  labs(caption = "Note: These estimates, with 84% confidence intervals, were generated from the models in Table 1") + theme(plot.caption = element_text(size = 8))
```


- The code below reproduces amended **Figure 2: The Effects of Racial Disparities Information (Non-Racially Prejudiced Whites)**

```{r include = T, tidy = T, results='asis'}
## plot the  estimated predicted values for non-racially prejudiced whites 
predictions %>%
  filter(Attitude == 0) %>%
  ggplot(aes(x=Treatment, y = predicted, group = dv_f)) + ggtitle("Figure 2 (amended): The Effects of Racial Disparities Information \n (Non-Racially Prejudiced Whites)") +
  geom_bar(aes(fill=Treatment), stat= "identity") +
  geom_errorbar( aes(x=Treatment, ymin=conf.low, ymax=conf.high), width=0.1) +
  facet_wrap(~dv_f) +
  ylim(0, 1) +
  theme_bw() + scale_fill_manual("Group", values = c(Treatment = "grey36", Control = "grey")) + ylab("Predicted Probability") + xlab("") +  labs(caption = "Note: These estimates, with 84% confidence intervals, were generated from the models in Table 1") + theme(plot.caption = element_text(size = 8))
```

- The code below reproduces amended **Figure 3: Difference in Average Treatment Effects: Prejudiced vs. Unprejudiced Whites**

```{r include = T, tidy = T, results='asis'}
## difference in average treatment effects to use the estimates with pooling standard errors
treat_test <- glht(masks_svyglm, linfct = c("Treatment:negstereotype_endorsement - Treatment == 0"))
treat_test <- confint(treat_test, level = .84)
masks_t <- as_tibble(treat_test$confint) %>%
  mutate(dv = "Wearing \n facemasks is not \n important")
treat_test <- glht(rights_svyglm, linfct = c("Treatment:negstereotype_endorsement - Treatment == 0"))
treat_test <- confint(treat_test, level = .84)
rights_t <- as_tibble(treat_test$confint) %>%
  mutate(dv = "Individual rights and \n freedom threatened")
treat_test <- glht(parks_svyglm, linfct = c("Treatment:negstereotype_endorsement - Treatment == 0"))
treat_test <- confint(treat_test, level = .84)
parks_t <- as_tibble(treat_test$confint) %>%
  mutate(dv = "Visit parks \n without any \n restrictions")
treat_test <- glht(socld_svyglm, linfct = c("Treatment:negstereotype_endorsement - Treatment == 0"))
treat_test <- confint(treat_test, level = .84)
socld_t <- as_tibble(treat_test$confint) %>%
  mutate(dv = "Black people rarely \n follow social \n distancing guidelines")
tests <- bind_rows(masks_t, rights_t, parks_t, socld_t)
## calculation of odd-ratios
tests = tests %>%
  mutate(e_est = exp(Estimate), 
         e_lwr = exp(lwr), 
         e_upr = exp(upr))
# tests %>%
#    relocate(dv) %>%
#    kableExtra::kable(format = "simple", digits = 3, caption = "Treatment:negstereotype_endorsement - Treatment w/ 84% CIs odds-ratios")
## plot using odd ratios
ggplot(tests, aes(x=as_factor(dv), y = e_est)) +
   geom_bar(stat= "identity") +
   geom_errorbar( aes(x=dv, ymin=e_lwr, ymax=e_upr), width=0.1) +
   ylab("odds-ratios") + 
   xlab("")+
   theme_bw() +  labs(caption = "Note: These estimates, with 84% confidence intervals, were generated from the models in Table 1") + ggtitle("Figure 3 (amended): Difference in Average Treatment Effects: \n Prejudiced vs. Unprejudiced Whites") +  theme(plot.caption = element_text(size = 8))
```

\clearpage 

## Additional Logistic Regression Models and Figures 

-  The code below reproduces **Table A2: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Pilot Study)**

- Note: Because Pilot Data do not include weights, the logistic regression models below do not use weights. 

```{r include = T, tidy = T, warning=F}
financial_glm_pilot <- glm(financiallypunished_dichotomous ~ newExperimentalConditions + newlazy_stereo + newExperimentalConditions * newlazy_stereo, family = binomial(link = "logit"), data = data_pilot)
home_glm_pilot <- glm(stayathome_dichotomous ~ newExperimentalConditions + newlazy_stereo + newExperimentalConditions * newlazy_stereo, family = binomial(link = "logit"), data = data_pilot)
shutdown_glm_pilot <- glm(shutdown_dichotomous ~ newExperimentalConditions + newlazy_stereo + newExperimentalConditions * newlazy_stereo, family = binomial(link = "logit"), data = data_pilot)
```

- Calculate one-tailed p-values for financially punished 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(financial_glm_pilot)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(financial_glm_pilot)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta < 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
financial_glm_pilot_onetailed <- pnorm(summary(financial_glm_pilot)$coefficients[,3], lower = T)
# financial_glm_pilot_onetailed
```

- Calculate one-tailed p-values for stay at home 

```{r include = T, tidy=T}
## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(home_glm_pilot)$coefficients[,3]))
## compare the glm p-values with manually calculated p-values
# summary(home_glm_pilot)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta < 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
home_glm_pilot_onetailed <- pnorm(summary(home_glm_pilot)$coefficients[,3], lower = T)
# home_glm_pilot_onetailed
```

- Calculate one-tailed p-values for shutdown

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(shutdown_glm_pilot)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(shutdown_glm_pilot)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta < 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
shutdown_glm_pilot_onetailed <- pnorm(summary(shutdown_glm_pilot)$coefficients[,3], lower = T)
# shutdown_glm_pilot_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(financial_glm_pilot, home_glm_pilot, shutdown_glm_pilot,
          title = "Table A2: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Pilot Study)", dep.var.labels = c("\\shortstack{Risky behavior \\\\ should be \\\\ financially punished}",               
"\\shortstack{People protesting \\\\ reopening the states \\\\ should stay home}", "\\shortstack{Non-Essential \\\\ businesses \\\\ should be \\\\ shut down}"),
          intercept.bottom = TRUE, digits = 2,
covariate.labels = c("Racial Disparities Information", "Negative stereotype endorsement", "Racial Disparities
                               Information X Negative Stereotype Endorsement", "Constant"), 
          no.space = TRUE, # to remove the spaces after each line of coefficients
          column.sep.width = "1pt", # to reduce column width
          font.size = "small", # to make font size smaller
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
           notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."), p.auto = FALSE, p = list(financial_glm_pilot_onetailed, home_glm_pilot_onetailed, shutdown_glm_pilot_onetailed), notes.append = FALSE)
```

\clearpage

-  The code below reproduces **Table A3: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Controlling for Total Cases Per County until 05-26-2020)**

- As a result of a data-use agreement with the National Opinion Research Center, variables related to zip code information and the county-level covid cases removed from the dataset. The Table cannot be replicated with the county-level covid cases. It is displayed without this variable and therefore replication code is the same with Table 1 in the main text. See the Appendix for the regression table with the control for county-level covid cases. 

```{r include = T, tidy = T, results='asis'}
stargazer(masks_svyglm, rights_svyglm, parks_svyglm, socld_svyglm,
          title = "Table A3: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Controlling for Total Cases Per County until 05-26-2020) [county-level covid cases removed]", 
          dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "Racial Disparities Information X\n Negative Stereotype Endorsement",  "Constant"),
          no.space = T, 
          column.sep.width = "1pt",
          font.size = "small", 
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."), p.auto = FALSE, p = list(masks_svyglm_onetailed, rights_svyglm_onetailed, parks_svyglm_onetailed, socld_svyglm_onetailed), notes.append = FALSE
)
```


\clearpage

The code below reproduces **Table A4:  The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Controlling for the Percentage of African Americans Living in the Respondents’ Zip Code)**

- As a result of a data-use agreement with the National Opinion Research Center, variables related to zip code information and the county-level covid cases removed from the dataset. The Table cannot be replicated with the zip code information. It is reproduced without this variable. See the Appendix for the regression table with the control variable. See the Appendix for the regression table with the control for zip code information. 

```{r include = T, tidy = T, results='asis'}
stargazer(masks_svyglm, rights_svyglm, parks_svyglm, socld_svyglm,
          title = "Table A4:  The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Controlling for the Percentage of African Americans Living in the Respondents’ Zip Code) [zip code information removed]", 
          dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "Racial Disparities Information X\n Negative Stereotype Endorsement",  "Constant"),
          no.space = T, 
          column.sep.width = "1pt",
          font.size = "small", 
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."), p.auto = FALSE, p = list(masks_svyglm_onetailed, rights_svyglm_onetailed, parks_svyglm_onetailed, socld_svyglm_onetailed), notes.append = FALSE
)
```

\clearpage

The code below reproduces **Table A5: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Controlling for State Mention)**

```{r include = T, tidy=T, warning=F}
masks_svyglm_mention <- svyglm(facemasks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement + statemention, family = binomial(link = "logit"), design = svydata)
rights_svyglm_mention <- svyglm(individualrights_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement + statemention, family = binomial(link = "logit"), design = svydata)
parks_svyglm_mention <- svyglm(visitparks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement + statemention, family = binomial(link = "logit"), design = svydata)
socld_svyglm_mention <- svyglm(Follow_Blacks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement + statemention, family = binomial(link = "logit"), design = svydata)
```

- Calculate one-tailed p-values for wearing masks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(masks_svyglm_mention)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(masks_svyglm_mention)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
masks_svyglm_mention_onetailed <- pnorm(summary(masks_svyglm_mention)$coefficients[,3], lower = F)
# masks_svyglm_mention_onetailed
```

- Calculate one-tailed p-values for individual rights and freedoms threatened 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(rights_svyglm_mention)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(rights_svyglm_mention)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## Store and use for assessing p-values in regression table
rights_svyglm_mention_onetailed <- pt(summary(rights_svyglm_mention)$coefficients[,3], rights_svyglm_mention$df.residual, lower = F)
# rights_svyglm_mention_onetailed
```

- Calculate one-tailed p-values for visit parks 

```{r include = T, tidy=T}
# # manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(parks_svyglm_mention)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(parks_svyglm_mention)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
parks_svyglm_mention_onetailed <- pnorm(summary(parks_svyglm_mention)$coefficients[,3], lower = F)
# parks_svyglm_mention_onetailed
```

- Calculate one-tailed p-values for following social distancing rules 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(socld_svyglm_mention)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(socld_svyglm_mention)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
socld_svyglm_mention_onetailed <- pnorm(summary(socld_svyglm_mention)$coefficients[,3], lower = F)
# socld_svyglm_mention_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(masks_svyglm_mention, rights_svyglm_mention, parks_svyglm_mention, socld_svyglm_mention,
           title = "Table A5: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Controlling for State Mention)", 
          dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
   covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "State Mention", "Racial Disparities Information X Negative Stereotype Endorsement", "Constant"),
 no.space = TRUE, # to remove the spaces after each line of coefficients
          column.sep.width = "1pt", # to reduce column width
          font.size = "small", # to make font size smaller
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."),
p.auto = FALSE, p = list(masks_svyglm_mention_onetailed, rights_svyglm_mention_onetailed, parks_svyglm_mention_onetailed, socld_svyglm_mention_onetailed), notes.append = FALSE
)
```

\clearpage 

The code below reproduces **Table A6: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Non-dichotomized Dependent Variables)** 

```{r include = T, tidy = T, results='asis', warning = F}
masks_svyglm_linear <- svyglm(facemasks ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, design = svydata)
rights_svyglm_linear <- svyglm(individualrights ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, design = svydata)
parks_svyglm_linear <- svyglm(visitparks ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, design = svydata)
socld_svyglm_linear <- svyglm(Follow_Blacks ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, design = svydata)
```

```{r include = T, tidy=T}
## get R^2 
# 1- masks_svyglm_linear$deviance/masks_svyglm_linear$null.deviance
# 1- rights_svyglm_linear$deviance/rights_svyglm_linear$null.deviance
# 1- parks_svyglm_linear$deviance/parks_svyglm_linear$null.deviance
# 1- parks_svyglm_linear$deviance/parks_svyglm_linear$null.deviance
rsq_tablea6 <- c("$R^2$",round(attr(summ(masks_svyglm_linear), "rsq"), 2), round(attr(summ(rights_svyglm_linear), "rsq"), 2), round(attr(summ(parks_svyglm_linear), "rsq"), 2) , round(attr(summ(socld_svyglm_linear), "rsq"), 2))
```

- Calculate one-tailed p-values for wearing masks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pt(-abs(summary(masks_svyglm_linear)$coefficients[,3]), masks_svyglm_linear$df.residual)
# ## compare the glm p-values with manually calculated p-values
# summary(masks_svyglm_linear)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
masks_svyglm_linear_onetailed <- pt(summary(masks_svyglm_linear)$coefficients[,3], masks_svyglm_linear$df.residual, lower = F)
# masks_svyglm_linear_onetailed
```

- Calculate one-tailed p-values for individual rights and freedoms threatened 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pt(-abs(summary(rights_svyglm_linear)$coefficients[,3]), rights_svyglm_linear$df.residual)
# ## compare the glm p-values with manually calculated p-values
# summary(rights_svyglm_linear)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
rights_svyglm_linear_onetailed <- pt(summary(rights_svyglm_linear)$coefficients[,3], rights_svyglm_linear$df.residual, lower = F)
# rights_svyglm_linear_onetailed
```

- Calculate one-tailed p-values for visit parks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pt(-abs(summary(parks_svyglm_linear)$coefficients[,3]), parks_svyglm_linear$df.residual)
# ## compare the glm p-values with manually calculated p-values
# summary(parks_svyglm_linear)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
parks_svyglm_linear_onetailed <- pt(summary(parks_svyglm_linear)$coefficients[,3], parks_svyglm_linear$df.residual, lower = F)
# parks_svyglm_linear_onetailed
```

- Calculate one-tailed p-values for following social distancing rules 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pt(-abs(summary(socld_svyglm_linear)$coefficients[,3]), socld_svyglm_linear$df.residual)
# ## compare the glm p-values with manually calculated p-values
# summary(socld_svyglm_linear)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
socld_svyglm_linear_onetailed <- pt(summary(socld_svyglm_linear)$coefficients[,3], socld_svyglm_linear$df.residual, lower = F)
# socld_svyglm_linear_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(masks_svyglm_linear, rights_svyglm_linear, parks_svyglm_linear, socld_svyglm_linear,
          title = "Table A6: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Non-dichotomized Dependent Variables)", dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "Racial Disparities
                               Information X Negative Stereotype Endorsement", "Constant"),
          no.space = TRUE, # to remove the spaces after each line of coefficients
          column.sep.width = "1pt", # to reduce column width
          font.size = "small", # to make font size smaller
           model.numbers = F, style = "apsr",  keep.stat = c("n"), add.lines = list(rsq_tablea6),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are OLS coefficients, with standard errors in parentheses."),
p.auto = FALSE, p = list(masks_svyglm_linear_onetailed, rights_svyglm_linear_onetailed, parks_svyglm_linear_onetailed, socld_svyglm_linear_onetailed), notes.append = FALSE
)
```

\clearpage 

The code below reproduces **Table A7: The Influence of Racial Disparities Information and Negative Stereotype Endorsement on COVID-19 Opinion (unweighted)**

```{r include = T, tidy = T, results='asis', warning = F}
masks_glm_nw <- glm(facemasks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), data = data)
rights_glm_nw <- glm(individualrights_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), data = data)
parks_glm_nw <- glm(visitparks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), data = data)
socld_glm_nw <- glm(Follow_Blacks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), data = data)
```

- Calculate one-tailed p-values for wearing masks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(masks_glm_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(masks_glm_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
masks_glm_nw_onetailed <- pnorm(summary(masks_glm_nw)$coefficients[,3], lower = F)
# masks_glm_nw_onetailed
```

- Calculate one-tailed p-values for individual rights and freedoms threatened 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(rights_glm_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(rights_glm_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
rights_glm_nw_onetailed <- pt(summary(rights_glm_nw)$coefficients[,3], rights_glm_nw$df.residual, lower = F)
# rights_glm_nw_onetailed
```

- Calculate one-tailed p-values for visit parks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(parks_glm_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(parks_glm_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
parks_glm_nw_onetailed <- pnorm(summary(parks_glm_nw)$coefficients[,3], lower = F)
# parks_glm_nw_onetailed
```

- Calculate one-tailed p-values for following social distancing rules 

```{r include = T, tidy=T}
## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(socld_glm_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(socld_glm_nw)$coefficients[,4]
```

```{r}
## manually calculate one-tailed p-values 
## For H1: beta > 0
# options(scipen = 999)
## Store and use for assessing p-values in regression table
socld_glm_nw_onetailed <- pnorm(summary(socld_glm_nw)$coefficients[,3], lower = F)
# socld_glm_nw_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(masks_glm_nw, rights_glm_nw, parks_glm_nw, socld_glm_nw,
          title = "Table A7: The Influence of Racial Disparities Information and Negative Stereotype Endorsement on COVID-19 Opinion (unweighted)", 
          dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "Racial Disparities
                               Information X Negative Stereotype Endorsement", "Constant"),
          no.space = TRUE, # to remove the spaces after each line of coefficients
          column.sep.width = "1pt", # to reduce column width
          font.size = "small", # to make font size smaller
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."),
p.auto = FALSE, p = list(masks_glm_nw_onetailed, rights_glm_nw_onetailed, parks_glm_nw_onetailed, socld_glm_nw_onetailed), notes.append = FALSE
)
```

\clearpage 

The code below reproduces **Table A8: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Controlling for State Mention) (unweighted)**

```{r include = T, tidy = T, results='asis', warning = F}
masks_glm_mention_nw <- glm(facemasks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement + statemention, family = binomial(link = "logit"), data = data)
rights_glm_mention_nw <- glm(individualrights_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement + statemention, family = binomial(link = "logit"), data = data)
parks_glm_mention_nw <- glm(visitparks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement + statemention, family = binomial(link = "logit"), data = data)
socld_glm_mention_nw <- glm(Follow_Blacks_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement + statemention, family = binomial(link = "logit"), data = data)
```

- Calculate one-tailed p-values for wearing masks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(masks_glm_mention_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(masks_glm_mention_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
masks_glm_mention_nw_onetailed <- pnorm(summary(masks_glm_mention_nw)$coefficients[,3], lower = F)
# masks_glm_mention_nw_onetailed
```

- Calculate one-tailed p-values for individual rights and freedoms threatened 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(rights_glm_mention_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(rights_glm_mention_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
rights_glm_mention_nw_onetailed <- pt(summary(rights_glm_mention_nw)$coefficients[,3], rights_glm_mention_nw$df.residual, lower = F)
# rights_glm_mention_nw_onetailed
```

- Calculate one-tailed p-values for visit parks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(parks_glm_mention_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(parks_glm_mention_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
parks_glm_mention_nw_onetailed <- pnorm(summary(parks_glm_mention_nw)$coefficients[,3], lower = F)
# parks_glm_mention_nw_onetailed
```

- Calculate one-tailed p-values for following social distancing rules 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(socld_glm_mention_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(socld_glm_mention_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
socld_glm_mention_nw_onetailed <- pnorm(summary(socld_glm_mention_nw)$coefficients[,3], lower = F)
# socld_glm_mention_nw_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(masks_glm_mention_nw, rights_glm_mention_nw, parks_glm_mention_nw, socld_glm_mention_nw,
           title = "Table A8: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Controlling for State Mention) (unweighted)", 
          dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
   covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "State Mention", "Racial Disparities Information X Negative Stereotype Endorsement", "Constant"),
 no.space = TRUE, # to remove the spaces after each line of coefficients
          column.sep.width = "1pt", # to reduce column width
          font.size = "small", # to make font size smaller
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."),
p.auto = FALSE, p = list(masks_glm_mention_nw_onetailed, rights_glm_mention_nw_onetailed, parks_glm_mention_nw_onetailed, socld_glm_mention_nw_onetailed), notes.append = FALSE
)
```

\clearpage 

The code below reproduces **Table A9: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Non-dichotomized Dependent Variables) (unweighted)**

```{r include = T, tidy = T, results='asis', warning = F}
masks_lm_nw <- lm(facemasks ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, data = data)
rights_lm_nw <- lm(individualrights ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, data = data)
parks_lm_nw <- lm(visitparks ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, data = data)
socld_lm_nw <- lm(Follow_Blacks ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, data = data)
```

 Calculate one-tailed p-values for wearing masks 

```{r include = T, tidy=T}
## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pt(-abs(summary(masks_lm_nw)$coefficients[,3]), masks_lm_nw$df.residual)
# ## compare the glm p-values with manually calculated p-values
# summary(masks_lm_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
masks_lm_nw_onetailed <- pt(summary(masks_lm_nw)$coefficients[,3], masks_lm_nw$df.residual, lower = F)
# masks_lm_nw_onetailed
```

- Calculate one-tailed p-values for individual rights and freedoms threatened 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pt(-abs(summary(rights_lm_nw)$coefficients[,3]), rights_lm_nw$df.residual)
# ## compare the glm p-values with manually calculated p-values
# summary(rights_lm_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## Store and use for assessing p-values in regression table
rights_lm_nw_onetailed <- pt(summary(rights_lm_nw)$coefficients[,3], rights_lm_nw$df.residual, lower = F)
# rights_lm_nw_onetailed
```

- Calculate one-tailed p-values for visit parks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pt(-abs(summary(parks_lm_nw)$coefficients[,3]), parks_lm_nw$df.residual)
# ## compare the glm p-values with manually calculated p-values
# summary(parks_lm_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
parks_lm_nw_onetailed <- pt(summary(parks_lm_nw)$coefficients[,3], parks_lm_nw$df.residual, lower = F)
# parks_lm_nw_onetailed
```

- Calculate one-tailed p-values for following social distancing rules 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pt(-abs(summary(socld_lm_nw)$coefficients[,3]), socld_lm_nw$df.residual)
# ## compare the glm p-values with manually calculated p-values
# summary(socld_lm_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
## store and use for assessing p-values in regression table
socld_lm_nw_onetailed <- pt(summary(socld_lm_nw)$coefficients[,3], socld_lm_nw$df.residual, lower = F)
# socld_lm_nw_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(masks_lm_nw, rights_lm_nw, parks_lm_nw, socld_lm_nw,
          title = "Table A9: The Influence of Racial Disparities Treatment and Negative Stereotype Endorsement on COVID-19 Opinion (Non-dichotomized Dependent Variables) (unweighted)", 
          dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "Racial Disparities Information X Negative Stereotype Endorsement", "Constant"),
          no.space = TRUE, # to remove the spaces after each line of coefficients
          column.sep.width = "1pt", # to reduce column width
          font.size = "small", # to make font size smaller
           model.numbers = F, style = "apsr",  keep.stat = c("n","rsq"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are OLS coefficients, with standard errors in parentheses."),
p.auto = FALSE, p = list(masks_lm_nw_onetailed, rights_lm_nw_onetailed, parks_lm_nw_onetailed, socld_lm_nw_onetailed), notes.append = FALSE
)
```

\clearpage 

The code below reproduces **Table A10: The Influence of Racial Disparities Treatment and Lazy Stereotype Endorsement on COVID-19 Opinion**

```{r include = T, tidy=T, warning=F}
masks_svyglm_lazy <- svyglm(facemasks_dichotomous ~ Treatment + lazystereotype2 + Treatment * lazystereotype2, family = binomial(link = "logit"), design = svydata)
rights_svyglm_lazy <- svyglm(individualrights_dichotomous ~ Treatment + lazystereotype2 + Treatment * lazystereotype2, family = binomial(link = "logit"), design = svydata)
parks_svyglm_lazy <- svyglm(visitparks_dichotomous ~ Treatment + lazystereotype2 + Treatment * lazystereotype2, family = binomial(link = "logit"), design = svydata)
socld_svyglm_lazy <- svyglm(Follow_Blacks_dichotomous ~ Treatment + lazystereotype2 + Treatment * lazystereotype2, family = binomial(link = "logit"), design = svydata)
```

- Calculate one-tailed p-values for wearing masks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(masks_svyglm_lazy)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(masks_svyglm_lazy)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
masks_svyglm_lazy_onetailed <- pnorm(summary(masks_svyglm_lazy)$coefficients[,3], lower = F)
# masks_svyglm_lazy_onetailed
```

- Calculate one-tailed p-values for individual rights and freedoms threatened 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(rights_svyglm_lazy)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(rights_svyglm_lazy)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
rights_svyglm_lazy_onetailed <- pnorm(summary(rights_svyglm_lazy)$coefficients[,3], lower = F)
# rights_svyglm_lazy_onetailed
```

- Calculate one-tailed p-values for visit parks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(parks_svyglm_lazy)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(parks_svyglm_lazy)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
# ## Store and use for assessing p-values in regression table
parks_svyglm_lazy_onetailed <- pnorm(summary(parks_svyglm_lazy)$coefficients[,3], lower = F)
# parks_svyglm_lazy_onetailed
```

- Calculate one-tailed p-values for following social distancing rules 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(socld_svyglm_lazy)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(socld_svyglm_lazy)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
socld_svyglm_lazy_onetailed <- pnorm(summary(socld_svyglm_lazy)$coefficients[,3], lower = F)
# socld_svyglm_lazy_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(masks_svyglm_lazy, rights_svyglm_lazy, parks_svyglm_lazy, socld_svyglm_lazy,
          title = "Table A10: The Influence of Racial Disparities Treatment and Lazy Stereotype Endorsement on COVID-19 Opinion", 
          dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "Racial Disparities Information X\n Negative Stereotype Endorsement",  "Constant"),
          no.space = T, 
          column.sep.width = "1pt",
          font.size = "small", 
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."), p.auto = FALSE, p = list(masks_svyglm_lazy_onetailed, rights_svyglm_lazy_onetailed, parks_svyglm_lazy_onetailed, socld_svyglm_lazy_onetailed), notes.append = FALSE
)
```

\clearpage 

The code below reproduces **Table A11: The Influence of Racial Disparities Treatment and Lazy Stereotype Endorsement on COVID-19 Opinion (unweighted)**

```{r include = T, tidy=T, warning=F}
masks_glm_lazy_nw <- glm(facemasks_dichotomous ~ Treatment + lazystereotype2 + Treatment * lazystereotype2, family = binomial(link = "logit"), data = data)
rights_glm_lazy_nw <- glm(individualrights_dichotomous ~ Treatment + lazystereotype2 + Treatment * lazystereotype2, family = binomial(link = "logit"), data = data)
parks_glm_lazy_nw <- glm(visitparks_dichotomous ~ Treatment + lazystereotype2 + Treatment * lazystereotype2, family = binomial(link = "logit"), data = data)
socld_glm_lazy_nw <- glm(Follow_Blacks_dichotomous ~ Treatment + lazystereotype2 + Treatment * lazystereotype2, family = binomial(link = "logit"), data = data)
```

- Calculate one-tailed p-values for wearing masks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(masks_glm_lazy_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(masks_glm_lazy_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
masks_glm_lazy_nw_onetailed <- pnorm(summary(masks_glm_lazy_nw)$coefficients[,3], lower = F)
# masks_glm_lazy_nw_onetailed
```

- Calculate one-tailed p-values for individual rights and freedoms threatened 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(rights_glm_lazy_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(rights_glm_lazy_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
rights_glm_lazy_nw_onetailed <- pnorm(summary(rights_glm_lazy_nw)$coefficients[,3], lower = F)
# rights_glm_lazy_nw_onetailed
```

- Calculate one-tailed p-values for visit parks 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(parks_glm_lazy_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(parks_glm_lazy_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
## store and use for assessing p-values in regression table
parks_glm_lazy_nw_onetailed <- pnorm(summary(parks_glm_lazy_nw)$coefficients[,3], lower = F)
# parks_glm_lazy_nw_onetailed
```

- Calculate one-tailed p-values for following social distancing rules 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(socld_glm_lazy_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(socld_glm_lazy_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
socld_glm_lazy_nw_onetailed <- pnorm(summary(socld_glm_lazy_nw)$coefficients[,3], lower = F)
# socld_glm_lazy_nw_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(masks_glm_lazy_nw, rights_glm_lazy_nw, parks_glm_lazy_nw, socld_glm_lazy_nw,
          title = "Table A11: The Influence of Racial Disparities Treatment and Lazy Stereotype Endorsement on COVID-19 Opinion (unweighted)", 
          dep.var.labels = c("\\shortstack{Wearing facemasks is not \\\\  important}",                       
"\\shortstack{Individual rights \\\\ and freedom threatened}", "\\shortstack{Visit parks \\\\ without any \\\\ restrictions}",
"\\shortstack{Black people rarely \\\\ follow social \\\\ distancing guidelines}"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "Racial Disparities Information X\n Negative Stereotype Endorsement",  "Constant"),
          no.space = T, 
          column.sep.width = "1pt",
          font.size = "small", 
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."), p.auto = FALSE, p = list(masks_glm_lazy_nw_onetailed, rights_glm_lazy_nw_onetailed, parks_glm_lazy_nw_onetailed, socld_glm_lazy_nw_onetailed), notes.append = FALSE
)
```

\clearpage 

The code below reproduces **Table A12: The Influence of Racial Disparities Treatment on Alternative Covid-19 Opinion Measures**

```{r include = T, tidy=T, warning=F}
usmeasures_svglm <- svyglm(usmeasures_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), design = svydata)
importancehome_svyglm <- svyglm(importancehome_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), design = svydata)
worrycovid_svyglm <- svyglm(worrycovid ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), design = svydata)
```

- Calculate one-tailed p-values for us measures 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(usmeasures_svglm)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(usmeasures_svglm)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
usmeasures_svglm_onetailed <- pnorm(summary(usmeasures_svglm)$coefficients[,3], lower = F)
# usmeasures_svglm_onetailed
```

- Calculate one-tailed p-values for importance home 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(importancehome_svyglm)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(importancehome_svyglm)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
importancehome_svyglm_onetailed <- pnorm(summary(importancehome_svyglm)$coefficients[,3], lower = F)
# importancehome_svyglm_onetailed
```

- Calculate one-tailed p-values for worry covid 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(worrycovid_svyglm)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(worrycovid_svyglm)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
# ## Store and use for assessing p-values in regression table
worrycovid_svyglm_onetailed <- pnorm(summary(worrycovid_svyglm)$coefficients[,3], lower = F)
# worrycovid_svyglm_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(usmeasures_svglm, importancehome_svyglm, worrycovid_svyglm,
          title = "Table A12: The Influence of Racial Disparities Treatment on Alternative Covid-19 Opinion Measures", 
          dep.var.labels = c("Slow the Spread", "Stay Home", "Too Long to Loosen Restrictions"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "Racial Disparities Information X\n Negative Stereotype Endorsement",  "Constant"),
          no.space = T, 
          column.sep.width = "1pt",
          font.size = "small", 
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."), p.auto = FALSE, p = list(usmeasures_svglm_onetailed, importancehome_svyglm_onetailed, worrycovid_svyglm_onetailed), notes.append = FALSE
)
```

\clearpage 

The code below reproduces **Table A13: The Influence of Racial Disparities Treatment on Alternative Covid-19 Opinion Measures (unweighted)**

```{r include = T, tidy=T, warning=F}
usmeasures_glm_nw <- glm(usmeasures_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), data = data)
importancehome_glm_nw <- glm(importancehome_dichotomous ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), data = data)
worrycovid_glm_nw <- glm(worrycovid ~ Treatment + negstereotype_endorsement + Treatment * negstereotype_endorsement, family = binomial(link = "logit"), data = data)
```

- Calculate one-tailed p-values for us measures 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(usmeasures_glm_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(usmeasures_glm_nw)$coefficients[,4]
```

```{r}
## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
usmeasures_glm_nw_onetailed <- pnorm(summary(usmeasures_glm_nw)$coefficients[,3], lower = F)
# usmeasures_glm_nw_onetailed
```

- Calculate one-tailed p-values for importance home 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values 
# options(scipen = 999)
# 2 * pnorm(-abs(summary(importancehome_glm_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(importancehome_glm_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table 
importancehome_glm_nw_onetailed <- pnorm(summary(importancehome_glm_nw)$coefficients[,3], lower = F)
# importancehome_glm_nw_onetailed
```

- Calculate one-tailed p-values for worry covid 

```{r include = T, tidy=T}
# ## manually calculate two-tailed p-values
# options(scipen = 999)
# 2 * pnorm(-abs(summary(worrycovid_glm_nw)$coefficients[,3]))
# ## compare the glm p-values with manually calculated p-values
# summary(worrycovid_glm_nw)$coefficients[,4]
```

```{r}
# ## manually calculate one-tailed p-values 
# ## For H1: beta > 0
# options(scipen = 999)
# ## store and use for assessing p-values in regression table
worrycovid_glm_nw_onetailed <- pnorm(summary(worrycovid_glm_nw)$coefficients[,3], lower = F)
# worrycovid_glm_nw_onetailed
```

```{r include = T, tidy = T, results='asis'}
stargazer(usmeasures_glm_nw, importancehome_glm_nw, worrycovid_glm_nw,
          title = "Table A13: The Influence of Racial Disparities Treatment on Alternative Covid-19 Opinion Measures (unweighted)", 
          dep.var.labels = c("Slow the Spread", "Stay Home", "Too Long to Loosen Restrictions"),
          intercept.bottom = TRUE, digits = 2,
          covariate.labels = c("Racial Disparities Information", "Negative Stereotype Endorsement", "Racial Disparities Information X\n Negative Stereotype Endorsement",  "Constant"),
          no.space = T, 
          column.sep.width = "1pt",
          font.size = "small", 
           model.numbers = F, style = "apsr",  keep.stat = c("n","ll"),
notes = c("Note: *p < 0.10, **p < 0.05, ***p < 0.01; one tailed p-values. Entries are logit coefficients, with standard errors in parentheses."), p.auto = FALSE, p = list(usmeasures_glm_nw_onetailed, importancehome_glm_nw_onetailed, worrycovid_glm_nw_onetailed), notes.append = FALSE
## replace the default p-values with one-tailed p-values
)
```


The code below reproduces **Figure A1: The Effects of Racial Disparities Information (Racially Prejudiced Whites) (unweighted)**

```{r include = T, tidy = T, results='asis'}
## unweighted glms from Table A7: masks_glm_nw, rights_glm_nw, parks_glm_nw, socld_glm_nw
## compute estimated predicted values 
masks_glm_nw_pr <- ggeffects::ggpredict(masks_glm_nw, terms = c("negstereotype_endorsement [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Wearing \n facemasks is not \n important")
rights_glm_nw_pr <- ggeffects::ggpredict(rights_glm_nw, terms = c("negstereotype_endorsement [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Individual rights and \n freedom threatened")
parks_glm_nw_pr <- ggeffects::ggpredict(parks_glm_nw, terms = c("negstereotype_endorsement [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Visit parks \n without any \n restrictions")
socld_glm_nw_pr <- ggeffects::ggpredict(socld_glm_nw, terms = c("negstereotype_endorsement [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Black people rarely \n follow social \n distancing guidelines")
# save the data frame
predictions_nw <- bind_rows(as_tibble(masks_glm_nw_pr), 
                        as_tibble(rights_glm_nw_pr), 
                        as_tibble(parks_glm_nw_pr), 
                        as_tibble(socld_glm_nw_pr))
predictions_nw <- predictions_nw %>%
  dplyr::rename(Treatment = group, 
         Attitude = x) %>%
  relocate(dv) %>%
  as_tibble() %>%
  mutate(Treatment = as.numeric(Treatment), 
         Attitude = as.numeric(Attitude), 
         Att_Treat = case_when(Attitude == 0 & Treatment == 1 ~ "Non-prejudiced, control", 
                               Attitude == 0 & Treatment == 2 ~ "Non-prejudiced, treatment", 
                               Attitude == 1 & Treatment == 1 ~ "Prejudiced, control", 
                               Attitude == 1 & Treatment == 2 ~ "Prejudiced, treatment"), 
         Att_Treat = as_factor(Att_Treat), 
         Figure = if_else(Attitude == 1, "Figure 1", "Figure 2"), 
         Treatment = as_factor(Treatment), 
         Treatment = fct_recode(Treatment, Control = "1", 
                                Treatment= "2"))
## create a factor variable for DVs
predictions_nw$dv_f <- factor(predictions_nw$dv, levels = c("Wearing \n facemasks is not \n important", "Individual rights and \n freedom threatened", "Black people rarely \n follow social \n distancing guidelines", "Visit parks \n without any \n restrictions"))
## plot the  estimated predicted values for racially prejudiced whites 
predictions_nw %>%
  filter(Attitude == 1) %>%
  ggplot(aes(x=Treatment, y = predicted, group = dv_f)) + ggtitle("Figure A1: The Effects of Racial Disparities Information \n (Racially Prejudiced Whites) (unweighted)") +
  geom_bar(aes(fill = Treatment), stat= "identity") +
  geom_errorbar( aes(x=Treatment, ymin=conf.low, ymax=conf.high), width=0.1) +
  facet_wrap(~dv_f) +
  theme_bw() +
  ylim(0, 1) + scale_fill_manual("Group", values = c(Treatment = "grey36", Control = "grey")) + ylab("Predicted Probability") + xlab("") +  labs(caption = "Note: These estimates, with 84% confidence intervals, were generated from the models in Appendix Table A7", size = 0.1) +  theme(plot.caption = element_text(size = 6))
```


- The code below reproduces **Figure A2: The Effects of Racial Disparities Information (Non-Racially Prejudiced Whites) (unweighted)**

```{r include = T, tidy = T, results='asis'}
## plot the  estimated predicted values for non-racially prejudiced whites 
predictions_nw %>%
  filter(Attitude == 0) %>%
  ggplot(aes(x=Treatment, y = predicted, group = dv_f)) + ggtitle("Figure A2: The Effects of Racial Disparities Information \n (Non-Racially Prejudiced Whites) (unweighted)") +
  geom_bar(aes(fill=Treatment), stat= "identity") +
  geom_errorbar( aes(x=Treatment, ymin=conf.low, ymax=conf.high), width=0.1) +
  facet_wrap(~dv_f) +
  ylim(0, 1) +
  theme_bw() + scale_fill_manual("Group", values = c(Treatment = "grey36", Control = "grey")) + ylab("Predicted Probability") + xlab("") +  labs(caption = "Note: These estimates, with 84% confidence intervals, were generated from the models in Appendix Table A7")  +   theme(plot.caption = element_text(size = 6))
```

\clearpage 

- The code below reproduces **Figure A3: Difference in Average Treatment Effects: Prejudiced vs. Unprejudiced Whites**

```{r include = T, tidy = T, results='asis'}
## unweighted glms from Table A7: masks_glm_nw, rights_glm_nw, parks_glm_nw, socld_glm_nw
## difference in average treatment effects to use the estimates with pooling standard errors
treat_test_nw <- glht(masks_glm_nw, linfct = c("Treatment:negstereotype_endorsement - Treatment == 0"))
treat_test_nw <- confint(treat_test_nw, level = .84)
masks_t_nw <- as_tibble(treat_test_nw$confint) %>%
  mutate(dv = "Wearing \n facemasks is not \n important")
treat_test_nw <- glht(rights_glm_nw, linfct = c("Treatment:negstereotype_endorsement - Treatment == 0"))
treat_test_nw <- confint(treat_test_nw, level = .84)
rights_t_nw <- as_tibble(treat_test_nw$confint) %>%
  mutate(dv = "Individual rights and \n freedom threatened")
treat_test_nw <- glht(parks_glm_nw, linfct = c("Treatment:negstereotype_endorsement - Treatment == 0"))
treat_test_nw <- confint(treat_test_nw, level = .84)
parks_t_nw <- as_tibble(treat_test_nw$confint) %>%
  mutate(dv = "Visit parks \n without any \n restrictions")
treat_test_nw <- glht(socld_glm_nw, linfct = c("Treatment:negstereotype_endorsement - Treatment == 0"))
treat_test_nw <- confint(treat_test_nw, level = .84)
socld_t_nw <- as_tibble(treat_test_nw$confint) %>%
  mutate(dv = "Black people rarely \n follow social \n distancing guidelines")
tests_nw <- bind_rows(masks_t_nw, rights_t_nw, parks_t_nw, socld_t_nw)
## calculation of odd-ratios
tests_nw <-  tests_nw %>%
  mutate(e_est = exp(Estimate), 
         e_lwr = exp(lwr), 
         e_upr = exp(upr))
# tests %>%
#    relocate(dv) %>%
#    kableExtra::kable(format = "simple", digits = 3, caption = "Treatment:negstereotype_endorsement - Treatment w/ 84% CIs odds-ratios")
## plot using odd ratios
ggplot(tests_nw, aes(x=as_factor(dv), y = e_est)) +
   geom_bar(stat= "identity") +
   geom_errorbar( aes(x=dv, ymin=e_lwr, ymax=e_upr), width=0.1) +
   ylab("odds-ratios") + 
   xlab("")+
   theme_bw() +  labs(caption = "Note: These estimates, with 84% confidence intervals, were generated from the models in Appendix Table A7") + ggtitle("Figure A3: Difference in Average Treatment Effects: \n Prejudiced vs. Unprejudiced Whites (unweighted)")  +  theme(plot.caption = element_text(size = 8))
```

\clearpage

- The code below reproduces **Figure A4: The Effects of Interaction Between Racial Disparities  Information and Exposure to Lazy Stereotype (Racially Prejudiced Whites)**

```{r include = T, tidy = T, results='asis'}
## svglms for lazy streotype from Table A10: masks_svyglm_lazy, rights_svyglm_lazy, parks_svyglm_lazy, socld_svyglm_lazy
## compute estimated predicted values 
masks_svyglm_lazy_pr<- ggeffects::ggpredict(masks_svyglm_lazy, terms = c("lazystereotype2 [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Wearing \n facemasks is not \n important")
rights_svyglm_lazy_pr <- ggeffects::ggpredict(rights_svyglm_lazy, terms = c("lazystereotype2 [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Individual rights and \n freedom threatened")
parks_svyglm_lazy_pr <- ggeffects::ggpredict(parks_svyglm_lazy, terms = c("lazystereotype2 [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Visit parks \n without any \n restrictions")
socld_svyglm_lazy_pr <- ggeffects::ggpredict(socld_svyglm_lazy, terms = c("lazystereotype2 [0,1]","Treatment"), ci.lvl = 0.84)  %>%
  mutate(dv = "Black people rarely \n follow social \n distancing guidelines")
# save the data frame
predictions_lazy <- bind_rows(as_tibble(masks_svyglm_lazy_pr), 
                        as_tibble(rights_svyglm_lazy_pr), 
                        as_tibble(parks_svyglm_lazy_pr), 
                        as_tibble(socld_svyglm_lazy_pr))
predictions_lazy <- predictions_lazy %>%
  dplyr::rename(Treatment = group, 
         Attitude = x) %>%
  relocate(dv) %>%
  as_tibble() %>%
  mutate(Treatment = as.numeric(Treatment), 
         Attitude = as.numeric(Attitude), 
         Att_Treat = case_when(Attitude == 0 & Treatment == 1 ~ "Non-prejudiced, control", 
                               Attitude == 0 & Treatment == 2 ~ "Non-prejudiced, treatment", 
                               Attitude == 1 & Treatment == 1 ~ "Prejudiced, control", 
                               Attitude == 1 & Treatment == 2 ~ "Prejudiced, treatment"), 
         Att_Treat = as_factor(Att_Treat), 
         Figure = if_else(Attitude == 1, "Figure 1", "Figure 2"), 
         Treatment = as_factor(Treatment), 
         Treatment = fct_recode(Treatment, Control = "1", 
                                Treatment= "2"))
## create a factor variable for DVs
predictions_lazy$dv_f <- factor(predictions_lazy$dv, levels = c("Wearing \n facemasks is not \n important", "Individual rights and \n freedom threatened", "Black people rarely \n follow social \n distancing guidelines", "Visit parks \n without any \n restrictions"))
## plot the  estimated predicted values for racially prejudiced whites 
predictions_lazy %>%
  filter(Attitude == 1) %>%
  ggplot(aes(x=Treatment, y = predicted, group = dv_f)) + ggtitle("Figure A4: The Effects of Racial Disparities Information \n (Racially Prejudiced Whites*)") +
  geom_bar(aes(fill = Treatment), stat= "identity") +
  geom_errorbar( aes(x=Treatment, ymin=conf.low, ymax=conf.high), width=0.1) +
  facet_wrap(~dv_f) +
  theme_bw() +
  ylim(0, 1) + scale_fill_manual("Group", values = c(Treatment = "grey36", Control = "grey")) + ylab("Predicted Probability") + xlab("") +  labs(caption = "Note: These estimates, with 84% confidence intervals, were generated from the models in Appendix Table A10")  +  theme(plot.caption = element_text(size = 6))
```

\clearpage

- The code below reproduces **The Effects of Racial Disparities Information (Non-Racially Prejudiced Whites*)**

```{r include = T, tidy = T, results='asis'}
## plot the  estimated predicted values for non-racially prejudiced whites 
predictions_lazy %>%
  filter(Attitude == 0) %>%
  ggplot(aes(x=Treatment, y = predicted, group = dv_f)) + ggtitle("Figure A5: The Effects of Racial Disparities Information \n (Non-Racially Prejudiced Whites*)") +
  geom_bar(aes(fill=Treatment), stat= "identity") +
  geom_errorbar( aes(x=Treatment, ymin=conf.low, ymax=conf.high), width=0.1) +
  facet_wrap(~dv_f) +
  ylim(0, 1) +
  theme_bw() + scale_fill_manual("Group", values = c(Treatment = "grey36", Control = "grey")) + ylab("Predicted Probability") + xlab("") +  labs(caption = "Note: These estimates, with 84% confidence intervals, were generated from the models in Appendix Table A10")  +  theme(plot.caption = element_text(size = 8))

```

\clearpage 

The code below reproduces **Figure A6: Difference in Average Treatment Effects: Prejudiced vs. Unprejudiced Whites**

```{r}
# Balance tests
t.test(AGE ~ Control, data)
d_age = 50.84488-51.09375
t.test(gender_new ~ Control, data)
d_gender = 0.5247525 - 0.4930556
t.test(ideo5 ~ Control, data)
d_ideo5 = 0.4653285 - 0.4637405
t.test(pid7 ~ Control, data)
d_pid7 =  0.5280641 - 0.5218978
t.test(educ ~ Control, data)
d_educ = 0.7271727 - 0.7233796
t.test(statemention ~ Control, data)
d_statemention = 0.1485149 - 0.1284722
t.test(South ~ Control, data)
d_South = 0.3003300- 0.3159722
t.test(INCOME ~ Control, data)
d_income = 10.60726-10.39236

dif_covariate <- rbind.data.frame(d_age, d_gender, d_ideo5, d_pid7, d_educ, d_statemention, d_South, d_income)
name_covairate <- rbind.data.frame("Age", "Gender", "Ideology", "Party Affiliation", "Education", "State Mentioned", "South", "Income")
lower_covariate <- rbind.data.frame(-3.063170, -0.04920263, -0.04676515, -0.04701312, -0.03802174, -0.03581462, -0.09040084, -0.4272374)
upper_covariate <- rbind.data.frame(2.565439, 0.11259647, 0.04994117, 0.05934578, 0.04560792, 0.07589988, 0.05911646, 0.8570366)
covariate <- cbind.data.frame(dif_covariate, name_covairate, lower_covariate, upper_covariate)
colnames(covariate) <- c("Difference", "Variable", "lower95", "upper95")
ggplot(data = covariate, aes(x= Variable, y= Difference))+ geom_point()+ geom_errorbar(aes(ymin=lower95, ymax=upper95),  width=0.2)+ ylab("Difference in Means") + theme_bw() + ggtitle("Figure A6: Difference in Average Treatment Effects:\n Prejudiced vs. Unprejudiced Whites") 
```

\clearpage 


The code below reproduces **Figure A7: Distribution of Opinion on Facemasks**

```{r, results='asis'}
ggplot(data = data, aes(facemasks)) + geom_bar()  + theme_bw() + ggtitle("Figure A7: Distribution of Opinion on Wearing Facemasks") + labs(caption = "Note: 0=Extremely Important, .25=Very Important, .5=Somewhat Important, .75=Not Very Important, 1=Not At All Important") + xlab("Wearing Facemasks") + ylab("Count")  +  theme(plot.caption = element_text(size = 8))
```

\clearpage 

The code below reproduces **Figure A8: Distribution of Opinion on Individual Rights and Freedoms**

```{r, results='asis'}
ggplot(data = data, aes(individualrights)) + geom_bar() + theme_bw() + ggtitle("Figure A8: Distribution of Opinion on Individual Rights and Freedoms") +  labs(caption = "Note: 0=Strongly Disagree, .25= Disagree, .5=Neither Agree Nor Disagree, .75=Agree, 1=Strongly Agree") + xlab("Individual rights and freedoms") + ylab("Count")  +  theme(plot.caption = element_text(size = 8))
```

\clearpage 

The code below reproduces **Figure A9: Distribution of Opinion on Visiting Parks**

```{r, results='asis'}
ggplot(data = data, aes(visitparks)) + geom_bar()  + theme_bw() + ggtitle("Figure A9: Distribution of Opinion on Visiting Parks") + labs(caption = "Note: 0=Not allowed at all restrictions, .5=Allowed with restrictions, 1=Allowed without any restrictions") + xlab("Visit Parks") + ylab("Count")  +  theme(plot.caption = element_text(size = 8))
```

\clearpage 

The code below reproduces **Figure A10: Distribution of the Perception that Black People Follow Social Distancing Guidelines**

```{r, results='asis'}
ggplot(data = data, aes(Follow_Blacks)) + geom_bar() + theme_bw() + ggtitle("Figure A10: Distribution of the Perception that Black People \n Follow Social Distancing Guidelines") + labs(captions = "Note: 0=Always, .25=Most of the time, .5=Half of the time, .75=Some of the time, 1= All of the Time") + xlab("Black People follow social distancing guidelines") + ylab("Count")  +  theme(plot.caption = element_text(size = 8))
```

